import { getDepositDeleteLogApi } from "@/api/waybillManagement/depositRegister";
import { Ref } from "vue";
export default function OperationHook(state: {
  searchForm: { pageNum: number; pageSize: number; total: number; beforePageNum: number };
  tableData: Ref<DepositRegister.ListRows[]>;
  tableRef: Ref<any>;
  loading: Ref<boolean>;
}) {
  const { searchForm, tableData, loading } = state;
  const getData = async () => {
    const params = {
      ...searchForm
    };
    loading.value = true;
    tableData.value = [];
    return getDepositDeleteLogApi(params)
      .then((res: any) => {
        const { code, data } = res;
        if (code === 200) {
          tableData.value = data.records || [];
          searchForm.beforePageNum = searchForm.pageNum;
          searchForm.total = Number(data.total);
        }
      })
      .finally(() => {
        loading.value = false;
      });
  };
  const searchHandle = async () => {
    searchForm.pageNum = 1;
    getData();
  };
  return {
    searchHandle,
    getData
  };
}
